package main

import (
	"fmt"
	"net/http"
	"encoding/json"
	"io/ioutil"
	"bytes"
)


type CustomMetricValue struct {
    Metric    string      `json:"metric"`
    Tags      string      `json:"tags"`
    Timestamp int64       `json:"timestamp"`  //10位(s)
    Value     interface{} `json:"value"`
    Type      string      `json:"type"`
    Step      int64         `json:"step"`
}



func main(){
    var mvs = make([]CustomMetricValue, 0)

    mv1 := CustomMetricValue{
        Metric: "request_cost2",
        Tags: "status_code=200,url=/v1/appliance/homegroup/relation,app_name=appliance-svc,server_ip=10.111.45.199,call_method=com.midea.iot.svc.appliance.controller.ApplianceController.getApplianceHomeGroupRelation,business_code=null",
        Timestamp: 1646531804,
        Value: 9.0,
        Type: "GAUGE",
        Step: 10,
    }
    mv2 := CustomMetricValue{
        Metric: "request_cost3",
        Tags: "status_code=200,url=/v1/appliance/homegroup/relation,app_name=appliance-svc,server_ip=10.111.45.199,call_method=com.midea.iot.svc.appliance.controller.ApplianceController.getApplianceHomeGroupRelation,business_code=null",
        Timestamp: 1646336820,  //如果时间很久会写不进去
        Value: 9.0,
        Type: "GAUGE",
        Step: 10,
    }
    mvs = append(mvs, mv1, mv2)

    client := &http.Client{}
    args ,_ :=json.Marshal(mvs)
    req, err := http.NewRequest("POST", "http://127.0.0.1:8433/api/push", bytes.NewBuffer([]byte(args)))
    if err != nil {
        fmt.Println(1111, err)
    }
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(22222)
        return
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(33333)
        return
    }
    fmt.Println(44444, string(body))
}